package com.gsx.mapper;

import com.gsx.entity.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CommentMapper {
    @Select("select * from comment where blog_id=#{blog_id} order by comment_createTime desc")
    public List<Comment> getCommentListById(Long blog_id);

    @Update(" insert into comment(comment_nickname,comment_email,comment_content,comment_avatar,comment_createTime,blog_id,parentComment_id,topParent_id,user_id) " +
            " values(#{comment_nickname},#{comment_email},#{comment_content},#{comment_avatar},#{comment_createTime},#{blog_id},#{parentComment_id},#{topParent_id},#{user_id}) ")
    public int saveComment(Comment comment);

    @Select(" <script> "+
            " select * from comment where 1=1  " +
            //" <if test='comment_content!=null'> and comment_content like '%${comment_content}%' </if> " +
            " <if test='comment_isdelete!=null'> and comment_isdelete=#{comment_isdelete} </if> " +
            " </script> ")
    public List<Comment> getCommentByBack(Comment comment);

    @Update("update comment set comment_isdelete=true where comment_id=#{id}")
    public int deleteComment(Long id);
}
